import { useState, useEffect } from 'react';
import { message } from 'antd';
import { fetchPostDetaillist } from '@/services/setting/salaryReference';

// 从服务器刷新邮件列表
const useEditionDetailList = (postitionSalaryVersion, pagination) => {
    const [loading, setLoading] = useState(false);
    const [resData, setResData] = useState([]);
    const [total, setTotal] = useState();

    const fetchData = async () => {
        setLoading(true);
        const { data, code, msg } = await fetchPostDetaillist({
            postitionSalaryVersion,
            changeType: 0,
            pageNo: pagination.current,
            pageSize: pagination.pageSize
        });
        if (code === 10000) {
            setResData(data.rows);
            setTotal(data.total);
        } else if (msg && msg.length > 0) {
            message.error(msg);
        }
        setLoading(false);
    };
    useEffect(() => {
        if (postitionSalaryVersion) {
            fetchData();
        }
    }, [postitionSalaryVersion, pagination]);
    return [total, resData, loading];
};

export default useEditionDetailList;
